<?php


namespace Sensio\Bundle\TrainingBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

use Sensio\Bundle\TrainingBundle\Contact\Contact;
use Sensio\Bundle\TrainingBundle\Form\ContactType;
use Sensio\Bundle\TrainingBundle\Service\ContactService;

/**
 * Description of ContactController
 *
 * @author DIDM4
 */
class ContactController extends Controller
{
    /**
     * @Route(
     *  name      = "contact",
     *  path      = "/contact",
     *  methods   = {"GET","POST"}
     * )
     * @Template
     * 
     */
    public function indexAction(Request $request)
    {
        $form = $this->createForm(new ContactType(), new Contact(), array('attr'=>array('novalidate'=>true)));
        $form->handleRequest($request);
        if($form->isValid())
        {
            $contact = $form->getData();
            
            $service = new ContactService($this->get('mailer'), $this->container->getParameter('training.contact_recipient'));
            $service->sendEmail($contact);
            
            return $this->redirect($this->generateUrl('contact_success'));
        }
        return array('form'=>$form->createView());
    }
    
    /**
     * @Route(
     *  name    = "contact_success",
     *  path    = "/contact/success",
     *  methods = "GET"
     * )
     * @Template
     */
    public function successAction()
    {
        return array();
    }
    //put your code here

}